<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>TengwarToPhoneticTranscriberTest</title>

<link rel="stylesheet"
	href="http://code.jquery.com/qunit/qunit-1.15.0.css">
<script src="http://code.jquery.com/qunit/qunit-1.15.0.js"></script>

<script src="../../main/js/util/Logger.js"></script>

<script src="../../main/js/TengwarToPhoneticTranscriber.js"></script>
<script src="../../main/js/TengwaRune.js"></script>

<script src="../../main/js/example/TengwarExampleTLOTR2.js"></script>

<script src="../../main/js/example/TengwarExampleTS1.js"></script>
<script src="../../main/js/example/TengwarExampleTS2.js"></script>

<script src="../../main/js/example/TengwarExampleUTONAME1.js"></script>
<script src="../../main/js/example/TengwarExampleUTONAME2.js"></script>

<script src="../../main/js/example/TengwarExampleTROTS1.js"></script>
<script src="../../main/js/example/TengwarExampleTROTS2.js"></script>

<script src="../../main/js/example/TengwarExampleTTOI1.js"></script>
<script src="../../main/js/example/TengwarExampleTTOI2.js"></script>

<script src="../../main/js/example/TengwarExampleTWOTR1.js"></script>
<script src="../../main/js/example/TengwarExampleTWOTR2.js"></script>

<script src="../../main/js/example/TengwarExampleSD1.js"></script>
<script src="../../main/js/example/TengwarExampleSD2.js"></script>

<script>
    var LOGGER = new Logger();

    /**************************************************************************
     * runesToPhonemes()
     */

    QUnit.test("runesToPhonemes() vowel + short carrier", function(assert)
    {
        // Setup.
        var transcriber = createTranscriber();
        var runes = [ [ TengwaRune.THREE_DOTS, TengwaRune.SHORT_CARRIER ], // a
        [ TengwaRune.DOT, TengwaRune.SHORT_CARRIER ], // e
        [ TengwaRune.ACUTE, TengwaRune.SHORT_CARRIER ], // i
        [ TengwaRune.LEFT_CURL, TengwaRune.SHORT_CARRIER ], // o
        [ TengwaRune.RIGHT_CURL, TengwaRune.SHORT_CARRIER ], // u
        ];

        // Run.
        var result = transcriber.runesToPhonemes(runes);

        // Verify.
        var expected = [ [ "a" ], [ "e" ], [ "i" ], [ "o" ], [ "u" ], ];
        verify(assert, result, expected);
    });

    QUnit.test("runesToPhonemes() vowel + short carrier + vowel", function(
            assert)
    {
        // Setup.
        var transcriber = createTranscriber();
        var runes = [
                [ TengwaRune.DOT, TengwaRune.SHORT_CARRIER,
                        TengwaRune.THREE_UNDER_DOTS ], // ea
                [ TengwaRune.ACUTE, TengwaRune.SHORT_CARRIER,
                        TengwaRune.THREE_UNDER_DOTS ], // ia
                [ TengwaRune.ACUTE, TengwaRune.SHORT_CARRIER,
                        TengwaRune.UNDER_DOT ], // ie
                [ TengwaRune.RIGHT_CURL, TengwaRune.SHORT_CARRIER,
                        TengwaRune.UNDER_DOT ], // ue
        ];

        // Run.
        var result = transcriber.runesToPhonemes(runes);

        // Verify.
        var expected = [ [ "e", "a" ], [ "i", "a" ], [ "i", "e" ],
                [ "u", "e" ], ];
        verify(assert, result, expected);
    });

    QUnit.test("Example TLOTR2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTLOTR2.RUNES,
                TengwarExampleTLOTR2.PHONEMES);
    });

    QUnit.test("Example TS1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTS1.RUNES,
                TengwarExampleTS1.PHONEMES);
    });

    QUnit.test("Example TS2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTS2.RUNES,
                TengwarExampleTS2.PHONEMES);
    });

    QUnit.test("Example UTONAME1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleUTONAME1.RUNES,
                TengwarExampleUTONAME1.PHONEMES);
    });

    QUnit.test("Example UTONAME2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleUTONAME2.RUNES,
                TengwarExampleUTONAME2.PHONEMES);
    });

    QUnit.test("Example TROTS1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTROTS1.RUNES,
                TengwarExampleTROTS1.PHONEMES);
    });

    QUnit.test("Example TROTS2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTROTS2.RUNES,
                TengwarExampleTROTS2.PHONEMES);
    });

    QUnit.test("Example TTOI1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTTOI1.RUNES,
                TengwarExampleTTOI1.PHONEMES);
    });

    QUnit.test("Example TTOI2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTTOI2.RUNES,
                TengwarExampleTTOI2.PHONEMES);
    });

    QUnit.test("Example TWOTR1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTWOTR1.RUNES,
                TengwarExampleTWOTR1.PHONEMES);
    });

    QUnit.test("Example TWOTR2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleTWOTR2.RUNES,
                TengwarExampleTWOTR2.PHONEMES);
    });

    QUnit.test("Example SD1 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleSD1.RUNES,
                TengwarExampleSD1.PHONEMES);
    });

    QUnit.test("Example SD2 runesToPhonemes()", function(assert)
    {
        testRunesToPhonemes(assert, TengwarExampleSD2.RUNES,
                TengwarExampleSD2.PHONEMES);
    });

    /**************************************************************************
     * Utility functions.
     */

    function createTranscriber()
    {
        return new TengwarToPhoneticTranscriber();
    }

    function testRunesToPhonemes(assert, runes, expected, useComparison)
    {
        // Setup.
        var transcriber = createTranscriber();

        // Run.
        var result = transcriber.runesToPhonemes(runes);

        // Verify.
        verify(assert, result, expected, useComparison);
    }

    function verify(assert, result, expected, useComparison)
    {
        assert.ok(result);
        assert.equal(result.length, expected.length);

        if (useComparison)
        {
            assert.equal(result, expected);
        }

        for (var i = 0; i < expected.length; i++)
        {
            if (Array.isArray(expected[i]))
            {
                verify(assert, result[i], expected[i], useComparison);
            }
            else
            {
                assert.equal(result[i], expected[i]);
            }
        }
    }
</script>
</head>
<body>
	<div id="qunit"></div>
</body>
</html>
